<?php
/**
 * Created by 张彪.
 * User: 小马出行
 * Date: 2018/5/22
 * Time: 13:14
 */
namespace app\admin\controller;
use app\admin\logic\LogLogic;
class AdminLog extends Base
{

    public $map=array();
    public function _initialize()
    {
        parent::_initialize();
        $base_condition = $this->base_condition;
        if($base_condition['admin_id'])$this->map['admin_id'] = $base_condition['admin_id'];
    }
    //管理员日志
    public function index()
    {
        $this->assign('url',url('table'));
        return view();
    }

    public function table()
    {
        $page = input('get.page');
        $limit = input('get.limit');
        $log_logic = new LogLogic();
        $res = $log_logic->getAdminLogInfo($this->map, '*', true, $page, $limit);
        $count = db('admin_log')->where($this->map)->count();
        $sql = db('admin_log')->where($this->map)->fetchSql(true)->count();
        $res = decode_array_2($res);
        echo json_encode(array(
            'code' => 0,
            'msg' => '',
            'sql' => $sql,
            'count' => $count,
            'data' => $res
        ));
    }

    public function search()
    {
        $page = input('get.page');
        $limit = input('get.limit');
        $start = strtotime(input('get.start'));
        $end = strtotime(input('get.end'));
        $name = trim(input('get.name'), ' ');
        $map = $this->map;
        if (input('get.start')) {
            $map['add_time'] = array('egt', $start);
        }
        if (input('get.end')) {
            $map['add_time'] = array('elt', $end);
        }
        if (input('get.start') && input('get.end')) {
            $map['add_time'] = array('between', array($start, $end));
        }
        $name && $map['admin_name'] = array('like', "%$name%");
        $log_logic = new LogLogic();
        $res = $log_logic->getAdminLogInfo($map, '*', true, $page, $limit);
        $count = db('admin_log')->where($map)->count();
        $res = decode_array_2($res);
        echo json_encode(array(
            'code' => 0,
            'msg' => '',
            'count' => $count,
            'data' => $res
        ));
    }
}